﻿<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery('@ID("#txt_file")').autocomplete({
            source: function (request, response) {
                jQuery.post('@Html.Raw(Url.Action(Loc.Act("Autocomplete").Ctrl("File").Area("Wizard").Localized()))', request, response);
            },
            minLength: 3,
            select: function (event, ui) {
                jQuery('@ID("#hidden_file")').val(ui.item.id);
            }
        });
    });
</script>
<table style="width: 100%;">
    <tr>
        <td style="vertical-align: top; width: 40%;">
            <form class="common-form" id="@ID("form")" action="@Url.Action(Loc.Act("AttachFile").Localized())" method="post">
                <input type="hidden" name="id" value="@JDM.Int32(Model.Post.EntityID)" />
                <ul id="@ID("file_list")">
                    <li>
                        <input id="@ID("hidden_file")" type="hidden" name="fileID" />
                        <input id="@ID("txt_file")" type="text" name="fileName" />
                    </li>
                </ul>
                <ul class="bar toolbar">
                    <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
                </ul>
            </form>
        </td>
        <td style="vertical-align: top; width: 60%; padding: 0 1em;">
            <ul class="cloud bordered">
            @foreach(var i in Model.Attachments)
            {
                <li>
                    <ul class="bar inlinebar">
                        <li><a href="@Url.Action(Loc.Act(MimeTypeHelper.IsImage(JDM.String(i.MimeType)) ? "Image" : "Download").Ctrl("Media").NoArea().Set(new
                        {
                            guid = JDM.Guid(i.Guid)
                        }).Localized())">&crarr;</a></li>
                        <li><a class="confirm" href="@Url.Action(Loc.Act("DetachFile").Set(new
                        {
                            id = JDM.Int32(Model.Post.EntityID), 
                            fileID = JDM.Int32(i.EntityID)
                        }).Localized())">x</a></li>
                    </ul>
                    @JDM.String(i.Name)
                </li>
            }
            </ul>
        </td>
    </tr>
</table>
